﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using RRRSRoguelike.Managers;
using RRRSRoguelikeData;

namespace RRRSRoguelike.Entities
{
    /// <summary>
    /// Player inherits from creature.
    /// </summary>
    public class Player : Creature
    {

        #region variables
        private DungeonManager dungeonManager = DungeonManager.Instance;
        #endregion

        #region constructor
        /// <summary>
        /// Initializes player
        /// </summary>
        /// <param name="p"></param>
        public Player(Point position)
            : base()
        {
            this.TileData = TileData.ReadTileDataFromXML(Properties.Settings.Default.CustomFolder + @"\Creatures\Player.xml");
            this.Position = position;
            Inventory = new List<Sword>();
        }
        #endregion

        #region properties
        public IList<Sword> Inventory { get; set; }
        #endregion

        #region methods
        // This should be two separate methods.  Add one to the tile.
        public Boolean MovePlayer(Direction direction,int distance = 1)
        {
            //check for valid move
            for (int i = distance; i > 0; i--)
            {
                Point newPosition = GetNewPosition(direction, i);
                if (dungeonManager.DungeonLevel.IsOKToMove(newPosition))
                {
                    Position = newPosition;
                    return true;
                }
            }
            return false;
        }

        private Point GetNewPosition(Direction direction, int distance)
        {
            Point newPoint = new Point(X, Y);
            switch (direction)
            {
                case Direction.N:
                    newPoint.Y -= distance;
                    break;
                case Direction.S:
                    newPoint.Y += distance;
                    break;
                case Direction.E:
                    newPoint.X += distance;
                    break;
                case Direction.W:
                    newPoint.X -= distance;
                    break;
            }
            return newPoint;
        }
        #endregion

    }
}
